home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
moveto.exe
/
MOVETO.DOC
< prev
Wrap
Text File
|
1992-02-23
|
3KB
|
57 lines
MOVETO
Moveto is a simple function for moving a string of characters in a c program
from one place to another. Unlike memcpy or strncpy, this little function
adds a fourth parameter. The explicit purpose of the extra parameter is to
provide a character which, when detected in the source string, will stop the
copying process prior to it itself being copied. It may be assembled for a
DOS or OS/2 program. It will also function as a DLL function under OS/2 or
Windows. (Tested under OS/2 1.3 and 1.2 but not under windows.)
Under normal circumstances, the presence of a zero byte ('\0') in the source
string will not have any effect on the operation of this function. If you
define the label "STOP_ON_ZERO_BYTE" (quotation marks not to be included)
either in the source program or on the control statement call to MASM, two
instructions will be inserted into the moveto function to stop the transfer
after a zero byte has been transferred.
To use the moveto function:
ptr = moveto(void *destination, void *source, int length, char stopper);
The characters are moved from source to destination until either the stopper
character is found or length characters are transferred. No checks are made
for stack overflow, inadaquate array sizes etc. You are on your own. The
source and destination array may overlap but undesired results can occur if
you do not know what you are doing. If the length parameter is zero, no bytes
are moved and the program exits properly.
The return value of the function is a pointer to the NEXT byte in the
destination string. This was supplied so that a zero byte could be placed at
this point. If no characters are moved the return value of the function is
a pointer to void *destination.
The program was written in MASM for execution speed. It could have been written
eaisily but with less efficiency in c.
You can assemble moveto by setting the argument string of MASM to
"/Mx {/Zi} /Dmemmodel={LARGE|SMALL|COMPACT|MEDIUM} {/DSTOP_ON_ZERO_BYTE}"
if you need it.
You may notice that all source memory references are in brackets. This is to
maintain consistency with the Borland Turbo Assembler and also to symbolically
stress that those operands are memory references.
Disclaimer: This program is in the public domain. It is not protected by
copyright or copywrong. You are free to use it without any fees being
paid or special homage being laid on me. I am not responsible for any
problems or damages which may occur from the use or non-use of this
program. It seems dishwasher and microwave safe, non-toxic, safe for
children etc. If you are learning assembly language it is probably
worth studying since it small enough to focus on each detail. It also
shows how pointers and values are used in conjunction with a c program.
Programmed By: A. L. Bender, M. D.
Bender Consulting
Released: 2/23/92